package cn.sumpu.app.coolsk.dao.impl;

import java.util.List;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.mybatis.spring.support.SqlSessionDaoSupport;

import cn.sumpu.app.coolsk.dao.TemplateDao;
import cn.sumpu.app.coolsk.domain.Template;
import cn.sumpu.app.coolsk.exception.AppBusinessException;

public class TemplateDaoImpl extends SqlSessionDaoSupport implements TemplateDao {

	private static Logger logger = LoggerFactory.getLogger(TemplateDaoImpl.class);

	

	@SuppressWarnings("unchecked")
	@Override
	public List<Template> getTemplate(Map<String, Object> map)
			throws AppBusinessException {
		try {
		   return getSqlSession().selectList("cn.sumpu.app.coolsk.persistence.TemplateMapper.getTemplate",map);
		} catch (Exception e) {
			if (logger.isErrorEnabled()) {
				logger.error("Query database failure.", e);
			}
			throw new AppBusinessException("Query database failure.", e);
		}
	}

	@Override
	public int getTemplateCount(Map<String, Object> map)
			throws AppBusinessException {
		try {
			Object obj = (Integer) getSqlSession()
					.selectOne("cn.sumpu.app.coolsk.persistence.TemplateMapper.getTemplateCount",
							map);
			return (Integer) (obj == null ? 0 : obj);
		} catch (Exception e) {
			if (logger.isErrorEnabled()) {
				logger.error("Query database failure.", e);
			}
			throw new AppBusinessException("Query database failure.", e);
		}
	}

	@Override
	public void updateTemplate(Template template) throws AppBusinessException {
		try {
			getSqlSession()
					.update("cn.sumpu.app.coolsk.persistence.TemplateMapper.updateTemplate",
							template);
		} catch (Exception e) {
			if (logger.isErrorEnabled()) {
				logger.error("Update database failure.", e);
			}
			throw new AppBusinessException("Update database failure.", e);
		}
	}

	
	
	

}
